﻿/* 测试歌词同步用的
 * By Eleven @2012/7/30
 * 以后歌词同步显示的要通过WPF做得很漂亮，所以现在写得很简陋，懒得改了。
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Text.RegularExpressions;
using ZMenFM.BASS;

namespace ZMenFM.Ramification.nBassTest
{
    public partial class LrcForm : Form
    {
        public static LrcForm instance = null;
        private synchroLrc synchrolrc = null;
        private Int32 channel = 0;

        private LrcForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 设置频道
        /// </summary>
        /// <param name="channel">频道</param>
        public void setChannel(Int32 channel)
        {
            this.channel = channel;
        }

        #region  获得LrcForm的实例
        /// <summary>
        /// 获得LrcForm的实例，为了方便采用单例模式，整个类只有一个实例
        /// </summary>
        /// <returns>LrcForm的实例</returns>
        public static LrcForm GetInstance(string lrc,Int32 channel)
        {
            if (instance == null)
            {
                instance = new LrcForm();
            }
            instance.synchrolrc = new synchroLrc(lrc);  //每次实例化都要重新设置歌词的内容
            instance.setChannel(channel);
            return instance;
        }
        #endregion
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            int time = (int)Player.Channel_GetPos(channel);
            label1.Text = FindLrc(time);
            if (Player.Channel_GetPos(channel) == Player.Channel_GetLength(channel))    //如果播放完毕则timer1不使用
            {
                timer1.Enabled = false;
            }
        }

        private string FindLrc(int time)
        {
            return synchrolrc.FindLrc(time);
        }

        public Timer GetTimer()
        {
            return timer1;
        }
    }
}